import org.molamil.acto.core.EventConstants;
import org.molamil.acto.core.ExternalConfProvider;
import org.molamil.acto.core.Logger;
import org.molamil.acto.pages.controller.AbstractPagesController;
import org.molamil.acto.pages.factory.XmlPagesFactory;
import org.molamil.commons.EventUtil;

/**
 * Page controller that loads XML configuration using <code>loadConf</code>.<br />
 * Dispatches:
 * <ul>
 * 	<li><code>onConfLoad</code>: The configuration has been succesfully loaded and parsed.</li>
 * 	<li><code>onConfLoadError</code>: There was a problem when loading the XML.</li>
 * </ul>
 *
 * @author Jorge Hernandez
 */
class org.molamil.acto.pages.controller.XmlPagesController extends AbstractPagesController 
														  implements ExternalConfProvider {
	
	
	// Properties
	
	private static var log:Logger = Logger.getLogger("XmlPagesController");
	
	
	// Constructor
	
	public function XmlPagesController() {
		log.debug("Constructor");	
	}
	
	
	// Functions
	
	/**
	 * Loads <cite>pages</cite> configuration from XML.
	 * 
	 * @param   source Object parameter with two usages:
	 * <ul>
	 * 	<li>As an <code>XML</code> object: Parses the XML data directly.</li>
	 * 	<li>As a <code>String</code> object: Loads the XML file located on source and 
	 * parses the content.</li>
	 * </ul>
	 */
	public function loadConf(source:Object):Void {
		log.info("loadConf()");
		factory = new XmlPagesFactory();
		EventUtil.propagate(XmlPagesFactory(factory), this, EventConstants.PAGES_CONF_LOAD, 
								  {target: this});
		EventUtil.propagate(XmlPagesFactory(factory), this, EventConstants.CONF_LOAD_ERROR, 
								  {target: this});
		XmlPagesFactory(factory).loadConf(source);
	}
	
	
}